<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>楼盘管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css?123456" media="all" /></head>
<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox" id="tool">
		<div class="layui-inline">
			<label class="layui-input-inline">楼盘名称</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input" name="name" placeholder="请输入标题" />
			</label>
			<label class="layui-input-inline">城市</label>
			<label class="layui-input-inline">
				<select name="cityId" id="cityId"></select>
			</label>
			<a class="layui-btn search_btn" lay-submit="" lay-filter="seacherBtn">搜索</a></div>
		<div class="layui-inline">
			<a class="layui-btn layui-btn-normal addBtn" data-title="添加" data-url="/hostItem/getEntity">添加</a></div>
	</blockquote>
	<table id="entityList" lay-filter="entityList"></table>
</form>
<script type="text/html" id="entityBar">
	<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="edit"> 编辑 </a>
	<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a >
</script>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">layui.use(['form','jquery', 'pageUtil', 'table', 'dateUtil','fileUtil'],
    function() {
        var $ = layui.jquery,
            form = layui.form,
            dateUtil = layui.dateUtil,
            table = layui.table,
			fileUtil = layui.fileUtil,
            pageUtil = layui.pageUtil;
        var tableIns = null;

        pageUtil.initDictByUrl("/hostCity/acceptSelect","host_city_type",
            function(dictData) {
                pageUtil.showDict($("#cityId"), pageUtil.aceeptDictContentList(dictData, "host_city_type"), "请选择城市");
                var url = "/hostItem/page";
                var cols = [{
                    type: 'checkbox',
                    fixed: 'left'
                },
                    {
                        type: 'numbers',
                        title: '序号'
                    },
                    {
                        field: 'name',
                        title: '楼盘名称',
						width: 250,
                        align: 'center'
                    },
                    {field: 'cityId', title: '城市',align:'center', width: 120,templet:function(d){
                        return pageUtil.aceeptDictContentName(dictData,"host_city_type",d.cityId);
                    }},
                    {field: 'coverImage', title: '封面图片',align:'center', width: 150,templet:function(d){
							return "<img lay-event ='showPicture'  src='"+d.coverImage+"' style='width:auto; max-width: 96%; height: 40px;'/>";
                    },width:100},
                    {
                        field: 'price',
                        title: '参考单价',
						width: 100,
                        align: 'center'
                    },
					{field: 'url',width:180, title: '链接', align:'center', templet:function(d){
						return '<input type="text" value="/pages/house/hostDesc?id='+d.id+'">';
					}},
                    {field: 'isRecommend',width:100, title: '推荐', align:'center', templet:function(d){
						if(d.isRecommend=="2"){
							return '<input class="editTypeOne" checked="true" data-id="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTypeOne" lay-event="editTypeOne" type="checkbox">';
						}else{
							return '<input class="editTypeOne" name="open" data-id="'+d.id+'" lay-skin="switch" lay-filter="switchTypeOne" lay-event="editTypeOne" type="checkbox">';
						}
					}},
					{field: 'isGrounding',width:100, title: '上架', align:'center', templet:function(d){
						if(d.isGrounding=="2"){
							return '<input class="editTypeTwo" checked="true" data-id="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTypeTwo" lay-event="editTypeTwo" type="checkbox">';
						}else{
							return '<input class="editTypeTwo" name="open" data-id="'+d.id+'" lay-skin="switch" lay-filter="switchTypeTwo" lay-event="editTypeTwo" type="checkbox">';
						}
					}},
                    {
                        field: 'createTime',
                        title: '创建时间',
                        width: 190,
                        align: 'center',
                        templet: function(d) {
                            return dateUtil.formatDate(new Date(d.createTime), "yyyy-MM-dd HH:mm:ss");
                        }
                    },
					{
						field: 'updateTime',
						title: '更新时间',
						width: 190,
						align: 'center',
						templet: function(d) {
							return dateUtil.formatDate(new Date(d.updateTime), "yyyy-MM-dd HH:mm:ss");
						}
					},
                    {
                        title: '更多',
                        width: 250,
                        align: "center",
                        fixed: 'right',
                        templet: function(d) {
                            return '<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="supplement"> 内容 </a>\
                                    <a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="layout"> 房型 </a >\
                                    <a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="more"> 更多 </a>\
                                    <a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="update"> 动态 </a>';
                        }
                    },
                    {
                        title: '操作',
                        width: 150,
                        templet: '#entityBar',
                        align: "center",
                        fixed: 'right'
                    }];
                tableIns = pageUtil.initDate(cols, url, true);
            });

        // type类型开启
        form.on('switch(switchTypeOne)', function(obj){
            // 获取当前控件
            var id = $(this).attr("data-id");
            console.log(id);
            var status = "1";
            if (this.checked){
                status = "2";
            }
            $.get("/hostItem/updateIsRecommend",{
                "id":id,
                "isRecommend":status,
            },function(result){
                if(1==result.code){
                    tableIns.reload();
                }else{
                    top.layer.msg(result.msg);
                }
            })
        });

		form.on('switch(switchTypeTwo)', function(obj){
			// 获取当前控件
			var id = $(this).attr("data-id");
			console.log(id);
			var status = "1";
			if (this.checked){
				status = "2";
			}
			$.get("/hostItem/updateIsGrounding",{
				"id":id,
				"isGrounding":status,
			},function(result){
				if(1==result.code){
					tableIns.reload();
				}else{
					top.layer.msg(result.msg);
				}
			})
		});

        table.on('tool(entityList)',
            function(obj) {
                var layEvent = obj.event,
                    data = obj.data;
                if(layEvent === 'supplement'){ //内容
                    pageUtil.editPopup("楼盘内容编辑", "/hostItemSupplement/getEntity?itemId=" + data.id);
                }else if (layEvent === 'showPicture') {
					fileUtil.imageSingleShow(data.coverImage);
				}else if(layEvent === 'layout'){ //房型
                    parent.tabAddUrl("/hostItemLayout/getPage?itemId="+data.id,"楼盘房型");
                }else if(layEvent === 'more'){ //更多
                    parent.tabAddUrl("/hostItemMore/getPage?itemId="+data.id,"楼盘更多");
                }else if(layEvent === 'update'){ //动态
                    parent.tabAddUrl("/hostItemUpdate/getPage?itemId="+data.id,"楼盘动态");
                }else if (layEvent === 'edit') {// 编辑
                    pageUtil.editPopup("编辑", "/hostItem/getEntity?id=" + data.id);
                } else if (layEvent === 'del') {
                    pageUtil.delete("确定删除该项吗？", "/hostItem/delete", {
                            "id": data.id,
                            "_method": "DELETE"
                        },
                        function(data) {
                            tableIns.reload();
                        });
                }
            });
    })</script>
</body>

</html>